package com.ww.springboot.boot.thread.study.executor.forkjoin;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.Stream;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-01-18 09:35
 */
public class ForkJoinDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        List<String> list = new ArrayList<>();
//
//        System.out.println(list.parallelStream().count());
//
//        System.out.println(Stream.of(list,list).parallel().count());

        ForkJoinWork forkJoinWork = new ForkJoinWork(0L, 10000000L);
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        ForkJoinTask<Long> submit = forkJoinPool.submit(forkJoinWork);
        forkJoinPool.execute(forkJoinWork);
        System.out.println(forkJoinWork.compute());

        System.out.println(forkJoinWork.isCompletedAbnormally());

        Thread.sleep(1000);

        //System.out.println(submit.get());

        System.out.println(forkJoinWork.isCompletedAbnormally());
        System.out.println(forkJoinWork.getException());
    }
}
